//src下实时刷新
var gulp = require('gulp');
var concat = require('gulp-concat');
var connect = require('gulp-connect');
var webserver = require('gulp-webserver');

gulp.task('connect', function() {
  connect.server({
    root: 'src',
    livereload: true,
    port:8090
  });
});

gulp.task('html', function () {
  gulp.src('./src/**/*.html')
    .pipe(connect.reload());
});

 
gulp.task('scripts', function() {
  // 按先后顺序合并
  return gulp.src(['./src/js/vue.js','./src/js/vue-resource.js'])
    .pipe(concat('main.js'))
    .pipe(gulp.dest('./src/libs/'));
});

// 自动打开浏览器
gulp.task('webserver', function() {
  gulp.src('src')
    .pipe(webserver({
      // 实时刷新
      livereload: true,
      directoryListing: true,
      open: true,
      port:8090
    }));
});

gulp.task('watch', function () {
  gulp.watch(['./src/**/*.html'], ['html']);
});

gulp.task('default', ['connect', 'watch','webserver','scripts']);